# !/usr/bin/python3
# -*- coding:utf-8 -*-
# Copyright 2021 The Chinaunicom Software Team. All rights reserved.
# @FileName: text_process.py
# @Author  : Dyu
# @Time    : 2021/7/9
"""
数据处理
"""
import numpy as np
import pandas as pd
import os, re, json, csv, heapq, codecs
from tqdm import tqdm
from collections import Counter
import jieba
import concurrent.futures
from gensim import corpora, models, similarities

def save_json(all_data, save_file):
    json_str = json.dumps(all_data, ensure_ascii=False)
    with codecs.open(save_file, mode='w', encoding='utf-8') as f:
        f.write(json_str)

def load_json(path):
    """
    Read json function
    :paramter:
    """
    with codecs.open(path, mode='r', encoding='utf-8') as fr:
        read_data = json.load(fr)
    return read_data


def csv_write(path, headers, rows):
    with open(path, 'w', encoding='utf-8', newline='') as fw:
        f_csv = csv.writer(fw)
        f_csv.writerow(headers)
        for row in rows:
            f_csv.writerow(row)


def data_process():
    """
    数据处理，严格按照切分列和top10工单生成json数据
    :return:
    """
    pass

def split_template():
    """
    切分模板, a.serv_content
    :return:
    """
    pass

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
    return False



def sort_max(temps, n):
    count_temps = dict(Counter(temps))
    max_n = heapq.nlargest(n, count_temps.items(), key=lambda x: x[1])
    top = [i[0] for i in max_n]
    return top, len(top)


if __name__ == '__main__':
    pass
